home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / formats / gif / gif2.std < prev    next >
Encoding:
Text File  |  1988-05-19  |  41.9 KB  |  1,268 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.                                G I F (tm)
  14.  
  15.                     Graphics Interchange Format (tm)
  16.  
  17.  
  18.  
  19.                            A standard for the
  20.                         storage and transmission
  21.                   of raster-based graphics information
  22.  
  23.  
  24.  
  25.  
  26.  
  27.                 * * * * PRELIMINARY REVIEW DRAFT * * * *
  28.  
  29.  
  30.  
  31.  
  32.                           Software Version 87a
  33.  
  34.                           Document Revision 1.0
  35.  
  36.                                 May 1988
  37.  
  38.  
  39.                 (c) 1987, 1988 by CompuServe Incorporated
  40.                            All rights reserved
  41.  
  42.  
  43.  
  44.         "GIF" and "Graphics Interchange Format" are trademarks of
  45.                         CompuServe Incorporated,
  46.                           an H&R Block Company
  47.  
  48.                        5000 Arlington Centre Blvd.
  49.                           Columbus, Ohio 43220
  50.                              (614) 457-8600
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  Disclaimer
  107.  
  108.  This document contains the latest information available at the time of
  109.  its creation.  However, CompuServe reserves the right to modify the
  110.  services described herein at any time, with or without written
  111.  notification.
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.                                        i
  139.  
  140.                                Table of Contents
  141.  
  142.  
  143.  Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   ii
  144.  
  145.  1.0  Introduction to GIF  . . . . . . . . . . . . . . . . . . . . .    1
  146.  
  147.       1.1  Changes to GIF  . . . . . . . . . . . . . . . . . . . . .    2
  148.  
  149.       1.2  Availability of GIF . . . . . . . . . . . . . . . . . . .    3
  150.  
  151.       1.3  Naming Files which Contain GIF Data . . . . . . . . . . .    4
  152.  
  153.       1.4  GIF Development Area  . . . . . . . . . . . . . . . . . .    5
  154.  
  155.  2.0  Format of GIF Data . . . . . . . . . . . . . . . . . . . . . .    6
  156.  
  157.       2.1  Signature/Version Block . . . . . . . . . . . . . . . . .    8
  158.  
  159.       2.2  Logical Screen Descriptor Block . . . . . . . . . . . . .   10
  160.  
  161.       2.3  Global Color Map Block  . . . . . . . . . . . . . . . . .   14
  162.  
  163.       2.4  Extension Block . . . . . . . . . . . . . . . . . . . . .   16
  164.  
  165.            2.4.1  Comment Extension Block  . . . . . . . . . . . . .   18
  166.  
  167.            2.4.2  Image Control Extension Block  . . . . . . . . . .   20
  168.  
  169.       2.5  Image Descriptor Block  . . . . . . . . . . . . . . . . .   23
  170.  
  171.            2.5.1  Interlaced Image Processing  . . . . . . . . . . .   27
  172.  
  173.       2.6  Local Color Map Block . . . . . . . . . . . . . . . . . .   29
  174.  
  175.       2.7  Raster Data Block . . . . . . . . . . . . . . . . . . . .   30
  176.  
  177.       2.8  Terminator Block  . . . . . . . . . . . . . . . . . . . .   32
  178.  
  179.  3.0  Encoding and Decoding  . . . . . . . . . . . . . . . . . . . .   33
  180.  
  181.       3.1  Compressing and Expanding Pixel Data  . . . . . . . . . .   35
  182.  
  183.       3.2  Byte Packaging  . . . . . . . . . . . . . . . . . . . . .   37
  184.  
  185.       3.3  Display Rendering . . . . . . . . . . . . . . . . . . . .   38
  186.  
  187.  4.0  Transmitting and Displaying GIF Data . . . . . . . . . . . . .   39
  188.  
  189.       4.1  GIF Enquiry Escape Sequence and Response  . . . . . . . .   40
  190.  
  191.       4.2  GIF Invocation Escape Sequences . . . . . . . . . . . . .   45
  192.  
  193.       4.3  Terminating Display of an Image . . . . . . . . . . . . .   46
  194.  
  195.       4.4  User Interface to Decoders  . . . . . . . . . . . . . . .   47
  196.  
  197.  Appendix:  Compression and Expansion Algorithm  . . . . . . . . .    A-1
  198.  
  199.  
  200.  GIF                                                   Revision 1.0, 5/88
  201.  
  202.  
  203.  
  204.  
  205.  
  206.                                       ii
  207.  
  208.  Preface
  209.  ------------------------------------------------------------------------
  210.  ------------------------------------------------------------------------
  211.  
  212.  Objectives      The objectives of this document are to:
  213.  
  214.                    . describe the Graphics Interchange Format (GIF)
  215.  
  216.                    . describe encoding and decoding 
  217.  
  218.                    . provide guidelines for application programs which
  219.                      transmit and display GIF data
  220.  
  221.                  The document describes version 87a of GIF.
  222.  
  223.                  --------------------------------------------------------
  224.  
  225.  Intended        The intended audience of this document is graphics
  226.  audience        programmers who write application programs which use GIF
  227.                  data.
  228.  
  229.                  --------------------------------------------------------
  230.  
  231.  Organization    A table of contents is provided to aid in locating
  232.                  specific information within the document.
  233.  
  234.                  The document contains an introduction to GIF which is
  235.                  followed by detailed information about GIF.  This
  236.                  detailed information is divided into three sections:
  237.  
  238.                    . Format of GIF data
  239.  
  240.                    . Encoding and decoding
  241.  
  242.                    . Transmitting and displaying GIF data
  243.  
  244.                  The compression and expansion algorithm applied to pixel
  245.                  data is included in the Appendix at the end of the
  246.                  document.
  247.  
  248.                  --------------------------------------------------------
  249.  
  250.  Conventions     The following conventions are used in this document:
  251.  
  252.                    . all numbers are decimal unless otherwise indicated
  253.  
  254.                    . a hexadecimal number is immediately followed by a
  255.                      lowercase "h"
  256.  
  257.                      Examples:  0h, 2Ch, FFh, A014h
  258.  
  259.                  --------------------------------------------------------
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.                                                               (continued)
  267.  
  268.  GIF                                                   Revision 1.0, 5/88
  269.  
  270.  
  271.  
  272.  
  273.  
  274.                                       iii
  275.  
  276.  Preface, continued
  277.  ------------------------------------------------------------------------
  278.  ------------------------------------------------------------------------
  279.  
  280.  Conventions       . exponentiation is represented in the standard
  281.  (continued)         mathematical superscripted fashion
  282.                                                                  (n+1)
  283.                      Example:  2 to the (n+1) power is shown as 2
  284.  
  285.                    . bits within a byte are numbered from right to left,
  286.                      starting with 0; bit 0 is the least significant bit
  287.                      and bit 7 is the most significant bit
  288.  
  289.                    . American Standard Code for Information Interchange
  290.                      (ASCII) character codes are often listed in
  291.                      parentheses after special characters (for example,
  292.                      ^) and character sequences which must be entered
  293.                      exactly as shown; this is done, in part, to avoid
  294.                      confusion when the document is transmitted
  295.                      electronically and special characters in the
  296.                      resulting file do not appear as they did in the
  297.                      original document
  298.  
  299.                  --------------------------------------------------------
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  GIF                                                   Revision 1.0, 5/88
  337.  
  338.  
  339.  
  340.  
  341.  
  342.                                        1
  343.  
  344.  1.0  Introduction to GIF
  345.  ------------------------------------------------------------------------
  346.  ------------------------------------------------------------------------
  347.  
  348.  What is GIF?    GIF is the acronym for Graphics Interchange Format.  GIF
  349.                  is a format which is used to store and transmit raster-
  350.                  based color and monochrome images in an efficient,
  351.                  hardware-independent manner.
  352.  
  353.                  --------------------------------------------------------
  354.  
  355.  History of GIF  GIF was developed by CompuServe Incorporated to address
  356.                  the need for a general color image definition and to
  357.                  facilitate the exchange of images between dissimilar
  358.                  computer hardware.  
  359.  
  360.                  --------------------------------------------------------
  361.  
  362.  Features        To encourage its use in a wide variety of applications,
  363.                  an explicit design goal of GIF is to provide a flexible
  364.                  and comprehensive set of features.  These features
  365.                  include:
  366.  
  367.                    . arbitrary image dimensions up to 64K pixels
  368.  
  369.                    . as many as 256 colors in a given image
  370.  
  371.                    . image colors chosen from a palette of over 16
  372.                      million colors 
  373.  
  374.                    . hardware-independent format
  375.  
  376.                    . reduced file sizes by use of advanced data
  377.                      compression techniques
  378.  
  379.                    . efficient decoding method which allows online
  380.                      viewing of images via networks
  381.  
  382.                                    . hardware-independent format not as efficient as a
  383.                      hardware-specific format
  384.  
  385.                    . transmission of GIF data requires full 8-bit
  386.                      transmission capability
  387.  
  388.                    . follows raster-based, as opposed to object-based,
  389.                      graphics philosophy
  390.  
  391.                    . quality of image display subject to limitations of
  392.                      display hardware
  393.  
  394.                  --------------------------------------------------------
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  GIF                                                   Revision 1.0, 5/88
  401.  
  402.  
  403.  
  404.  
  405.  
  406.                                        2
  407.  
  408.  1.1  Changes to GIF
  409.  ------------------------------------------------------------------------
  410.  ------------------------------------------------------------------------
  411.  
  412.  Controlling     Changes to the GIF definition are under the control of
  413.  changes         CompuServe and will remain so until GIF is proposed or
  414.                  adopted as an official industry standard.  Changes are
  415.                  expected every 12-18 months to address the needs of the
  416.                  evolving graphics marketplace.
  417.  
  418.                  --------------------------------------------------------
  419.  
  420.  User            Users are discouraged from making ad hoc changes to the
  421.  enhancements    GIF definition, not only to avoid the "multiple-variant"
  422.                  syndrome other public domain computer standards suffer
  423.                  from, but also to keep in the spirit of machine and
  424.                  application independence central to the GIF effort.
  425.  
  426.                  --------------------------------------------------------
  427.  
  428.  Proposing       Users are encouraged to submit their proposals for
  429.  changes         changes to the GIF definition.  Each proposal should
  430.                  outline the change and the reasoning behind it. 
  431.                  Proposals may be submitted via U.S. mail to:
  432.  
  433.                       Manager of Graphics Technology
  434.                       CompuServe Incorporated
  435.                       5000 Arlington Centre Boulevard
  436.                       Columbus, Ohio  43220
  437.  
  438.                  Proposals may also be submitted in the GIF development
  439.                  area of the CompuServe Information Service (CIS) (see
  440.                  section 1.4, page 5).
  441.  
  442.                  --------------------------------------------------------
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  GIF                                                   Revision 1.0, 5/88
  469.  
  470.  
  471.  
  472.  
  473.  
  474.                                        3
  475.  
  476.  1.2  Availability of GIF
  477.  ------------------------------------------------------------------------
  478.  ------------------------------------------------------------------------
  479.  
  480.  Availability    GIF is available for use in any application program
  481.  of GIF          without royalties or licensing restrictions.  CompuServe
  482.                  does ask, however, that any such program include a
  483.                  trademark statement attributing ownership of GIF to
  484.                  CompuServe Incorporated.
  485.  
  486.                  --------------------------------------------------------
  487.  
  488.  Support for     GIF support is available in the GIF development area of
  489.  GIF             the CompuServe Information Service (CIS) (see section
  490.                  1.4, page 5).
  491.  
  492.                  --------------------------------------------------------
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  GIF                                                   Revision 1.0, 5/88
  537.  
  538.  
  539.  
  540.  
  541.  
  542.                                        4
  543.  
  544.  1.3  Naming Files which Contain GIF Data
  545.  ------------------------------------------------------------------------
  546.  ------------------------------------------------------------------------
  547.  
  548.  Overview        Guidelines for naming files which contain GIF data are
  549.                  provided in this section.  Use of these guidelines is
  550.                  suggested; however, their use is not necessary for
  551.                  conformance with the GIF standard.
  552.  
  553.                  --------------------------------------------------------
  554.  
  555.  In MS-DOS and   Use ".GIF" as the extension for a file which contains
  556.  similar         GIF data when in MS-DOS or a similar operating system.
  557.  operating
  558.  systems
  559.                  --------------------------------------------------------
  560.  
  561.  With the Apple  Classify a file which contains GIF data as type "GIFf"
  562.  Macintosh       when using software for the Apple Macintosh which reads
  563.                  or writes such files.  Doing this helps to prevent
  564.                  problems when using communications programs to transfer
  565.                  files.
  566.  
  567.                  No official GIF icon has been defined to represent files
  568.                  which contain GIF data.  Any icon used to represent such 
  569.                  files should include the characters "GIF".
  570.  
  571.                  --------------------------------------------------------
  572.  
  573.  With other      When naming files which contain GIF data, use a unique
  574.  operating       and consistent file identification within the structure
  575.  systems         of the local file identification conventions.
  576.  
  577.                  --------------------------------------------------------
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  GIF                                                   Revision 1.0, 5/88
  605.  
  606.  
  607.  
  608.  
  609.  
  610.                                        5
  611.  
  612.  1.4  GIF Development Area
  613.  ------------------------------------------------------------------------
  614.  ------------------------------------------------------------------------
  615.  
  616.  What is the     The GIF development area is an area within the
  617.  GIF             CompuServe Information Service (CIS) where CompuServe
  618.  development     provides GIF support and incentives for its use by
  619.  area?           independent software developers.  The GIF development
  620.                  area is located in the Pictures Support Forum.
  621.  
  622.                  --------------------------------------------------------
  623.  
  624.  Benefits of     Benefits of joining the GIF development area include:
  625.  joining the
  626.  area              . free access to the area
  627.  
  628.                    . access to GIF source code modules
  629.  
  630.                    . access to GIF utilities and working programs
  631.  
  632.                    . support from CompuServe associates
  633.  
  634.                    . support from other GIF developers
  635.  
  636.                    . periodic electronic conferences with CompuServe
  637.                      associates and other GIF developers
  638.  
  639.                  --------------------------------------------------------
  640.  
  641.  Requirements    Members of the GIF development area must:
  642.  
  643.                    . be CIS subscribers
  644.  
  645.                    . adhere to the published GIF standard
  646.  
  647.                    . include, in any application program developed using
  648.                      GIF, a trademark statement attributing ownership of
  649.                      GIF to CompuServe Incorporated 
  650.  
  651.                  --------------------------------------------------------
  652.  
  653.  How to join     To become a member of the GIF development area:
  654.  
  655.                   1.  Access the Pictures Support Forum (direct access
  656.                       may be obtained by typing the CIS command "GO
  657.                       PICS").
  658.  
  659.                   2.  Join the Pictures Support Forum by following the
  660.                       instructions provided in that forum.
  661.  
  662.                   3.  Enter library 1 of the Pictures Support Forum
  663.                       (General/Utilities).
  664.  
  665.                   4.  Read the file "DEVGIF.TXT" and follow its
  666.                       instructions for joining the GIF development area.
  667.  
  668.                  Once your application has been approved, access will be
  669.                  granted to the GIF development area.
  670.                  --------------------------------------------------------
  671.  
  672.  GIF                                                   Revision 1.0, 5/88
  673.  
  674.  
  675.  
  676.  
  677.  
  678.                                        6
  679.  
  680.  2.0  Format of GIF Data 
  681.  ------------------------------------------------------------------------
  682.  ------------------------------------------------------------------------
  683.  
  684.  Overview        On a display surface, an image is a rectangular array of
  685.                  pixels.  This pixel array may be stored in a file as a
  686.                  series of pixels.  GIF defines a format for storing
  687.                  pixels and the information needed to interpret and
  688.                  display the pixels.
  689.  
  690.                  A file may be comprised entirely of GIF data;
  691.                  conversely, GIF data may be one component of a much
  692.                  larger file.
  693.  
  694.                  --------------------------------------------------------
  695.  
  696.  Pixels          With GIF, an image is stored as a series of pixels. 
  697.                  These pixels serve as index values into a color map. 
  698.                  The color map defines the color assigned to each pixel.
  699.  
  700.                  Pixels are stored without any indication of position
  701.                  within the image. 
  702.  
  703.                  --------------------------------------------------------
  704.  
  705.  Color maps      A color map is a series of red, green, and blue
  706.                  intensity values that defines the individual colors
  707.                  which may appear in an image.  Pixels serve as index
  708.                  values into the color map.  
  709.  
  710.                  GIF data may include a global color map; this global
  711.                  map is used for each image when no local color map is
  712.                  associated with the image.  A local color map is a
  713.                  color map that is used for only one image.  When no
  714.                  global or local color map is present, pixels cannot be
  715.                  mapped to color definitions, and interpretation of
  716.                  pixels is indeterminate.
  717.  
  718.                  --------------------------------------------------------
  719.  
  720.  Format of GIF   GIF data is comprised of functional data blocks, some of
  721.  data            which may be repeated, others of which are optional. 
  722.                  These blocks are shown on the following page and are
  723.                  described in detail in the following sections.
  724.  
  725.                  --------------------------------------------------------
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.                                                               (continued)
  739.  
  740.  GIF                                                   Revision 1.0, 5/88
  741.  
  742.  
  743.  
  744.  
  745.  
  746.                                        7
  747.  
  748.  2.0  Format of GIF Data, continued
  749.  ------------------------------------------------------------------------
  750.  ------------------------------------------------------------------------
  751.  
  752.  Format of GIF                          GIF Data
  753.  data
  754.  (continued)     +---------------------------------+
  755.                  |     Signature/Version Block     |
  756.                  +---------------------------------+ -+
  757.                  | Logical Screen Descriptor Block |  | Logical Screen
  758.                  +---------------------------------+  | Block
  759.                  |Global Color Map Block (optional)|  |
  760.                  +---------------------------------+ -+
  761.                  |   Extension Block (optional)    | -- may be repeated
  762.                  +---------------------------------+ -+
  763.                  |     Image Descriptor Block      |  |
  764.                  +---------------------------------+  | Image Block;
  765.                  |Local Color Map Block (optional) |  | may be repeated
  766.                  +---------------------------------+  |
  767.                  |      Raster Data Block(s)       |  |
  768.                  +---------------------------------+ -+
  769.                  |   Extension Block (optional)    | -- may be repeated
  770.                  +---------------------------------+
  771.                  |        Terminator Block         |
  772.                  +---------------------------------+
  773.  
  774.                  --------------------------------------------------------
  775.  
  776.  Data types      Data type refers to the structure of a data segment and
  777.                  determines how that data segment is interpreted.  The
  778.                  data types used in GIF data are:
  779.  
  780.                  +---------+--------------------------------------------+
  781.                  |Data Type|                Description                 |
  782.                  +---------+--------------------------------------------+
  783.                  |byte     |8-bit unsigned value; may represent charac- |
  784.                  |         |ters or numeric values between 0 and 255    |
  785.                  +---------+--------------------------------------------+
  786.                  |field    |2 to 7 contiguous bits within a given byte; |
  787.                  |         |interpretation depends on the quantity      |
  788.                  |         |represented                                 |
  789.                  +---------+--------------------------------------------+
  790.                  |flag     |1-bit value which represents a logical true |
  791.                  |         |(1) or false (0)                            |
  792.                  +---------+--------------------------------------------+
  793.                  |integer  |16-bit unsigned integer value; always stored|
  794.                  |         |least significant byte first                |
  795.                  +---------+--------------------------------------------+
  796.  
  797.                  --------------------------------------------------------
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  GIF                                                   Revision 1.0, 5/88
  809.  
  810.  
  811.  
  812.  
  813.  
  814.                                        8
  815.  
  816.  2.1  Signature/Version Block
  817.  ------------------------------------------------------------------------
  818.  ------------------------------------------------------------------------
  819.  
  820.  Overview        The Signature/Version Block:
  821.  
  822.                    . identifies a block of data as GIF data
  823.  
  824.                    . indicates the version of GIF used to define the
  825.                      data
  826.  
  827.                  --------------------------------------------------------
  828.  
  829.  Use of the      Decoding software may use the Signature/Version Block to
  830.  Signature/      determine the version of GIF used to define the data.  
  831.  Version Block   This information may be needed by the decoding software
  832.                  to determine if it is able to process the data; if the
  833.                  decoding software was built from a version of GIF which
  834.                  is older than that used to define the data, the
  835.                  decoding software may not be able to adequately support
  836.                  features of the newer definition.
  837.  
  838.                  --------------------------------------------------------
  839.  
  840.  Existence       The Signature/Version Block is required.  It must be the
  841.                  first block in the GIF data.
  842.  
  843.                  --------------------------------------------------------
  844.  
  845.  Size            The Signature/Version Block is six bytes long.
  846.  
  847.                  --------------------------------------------------------
  848.  
  849.  Structure of    The structure of the Signature/Version Block is
  850.  the Signature/  illustrated below.
  851.  Version Block
  852.                                Bits
  853.  
  854.                    7   6   5   4   3   2   1   0    Byte #
  855.                  +---+---+---+---+---+---+---+---+
  856.                  |                               |    1
  857.                  +-                             -+
  858.                  |           Signature           |    2
  859.                  +-                             -+
  860.                  |                               |    3
  861.                  +-------------------------------+
  862.                  |                               |    4
  863.                  +-                             -+
  864.                  |            Version            |    5
  865.                  +-                             -+
  866.                  |                               |    6
  867.                  +-------------------------------+ 
  868.  
  869.                  --------------------------------------------------------
  870.  
  871.  
  872.  
  873.  
  874.                                                               (continued)
  875.  
  876.  GIF                                                   Revision 1.0, 5/88
  877.  
  878.  
  879.  
  880.  
  881.  
  882.                                        9
  883.  
  884.  2.1  Signature/Version Block, continued
  885.  ------------------------------------------------------------------------
  886.  ------------------------------------------------------------------------
  887.  
  888.  Structure of    where:
  889.  the
  890.  Signature/      +------------+-------+---------------------------------+
  891.  Version Block   |    Item    | Data  |           Description           |
  892.  (continued)     |            | Type  |                                 |
  893.                  +------------+-------+---------------------------------+
  894.                  |Signature   |bytes  |ASCII text characters "GIF"      |
  895.                  |            |       |(47h 49h 46h); identifies the    |
  896.                  |            |       |block as GIF data                |
  897.                  +------------+-------+---------------------------------+
  898.                  |Version     |bytes  |3-byte string of ASCII characters|
  899.                  |            |       |which identifies the version of  |
  900.                  |            |       |GIF used to define the data; the |
  901.                  |            |       |first two characters are the     |
  902.                  |            |       |year of the definition and the   |
  903.                  |            |       |last character is the lowercase  |
  904.                  |            |       |alphabetic version sequence      |
  905.                  |            |       |number; the current version      |
  906.                  |            |       |is 87a (38h 37h 61h)             |
  907.                  +------------+-------+---------------------------------+
  908.  
  909.                  --------------------------------------------------------
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  GIF                                                   Revision 1.0, 5/88
  945.  
  946.  
  947.  
  948.  
  949.  
  950.                                       10
  951.  
  952.  2.2  Logical Screen Descriptor Block
  953.  ------------------------------------------------------------------------
  954.  ------------------------------------------------------------------------
  955.  
  956.  Overview        The Logical Screen Descriptor Block:
  957.  
  958.                    . defines the logical screen
  959.  
  960.                    . provides information about the global color map
  961.  
  962.                    . provides information about image pixels
  963.  
  964.                    . specifies the background color
  965.  
  966.                    . specifies the pixel aspect ratio
  967.  
  968.                  --------------------------------------------------------
  969.  
  970.  What is the     The logical screen is the area required to contain the
  971.  logical         images in a block of GIF data.  The dimensions of the
  972.  screen?         logical screen are specified in the Logical Screen
  973.                  Descriptor Block.  
  974.  
  975.                  Note that the logical screen may be larger than the
  976.                  display surface.
  977.  
  978.                  --------------------------------------------------------
  979.  
  980.  What is pixel   Pixel aspect ratio is the ratio of a pixel's height as
  981.  aspect ratio?   compared to its width, and it serves as an indication of
  982.                  the pixel's shape.  A pixel aspect ratio of 1.0 defines
  983.                  a square pixel; a ratio of 2.0 defines a pixel which is
  984.                  twice as high as it is wide.
  985.  
  986.                  --------------------------------------------------------
  987.  
  988.  Existence       The Logical Screen Descriptor Block is required.  It
  989.                  must immediately follow the Signature/Version Block.
  990.  
  991.                  --------------------------------------------------------
  992.  
  993.  Size            The Logical Screen Descriptor Block is seven bytes long.
  994.  
  995.                  --------------------------------------------------------
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.                                                               (continued)
  1011.  
  1012.  GIF                                                   Revision 1.0, 5/88
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.                                       11
  1019.  
  1020.  2.2  Logical Screen Descriptor Block, continued
  1021.  ------------------------------------------------------------------------
  1022.  ------------------------------------------------------------------------
  1023.  
  1024.  Structure of    The structure of the Logical Screen Descriptor Block is
  1025.  the Logical     illustrated below.
  1026.  Screen
  1027.  Descriptor                    Bits
  1028.  Block
  1029.                    7   6   5   4   3   2   1   0    Byte #
  1030.                  +---+---+---+---+---+---+---+---+
  1031.                  |                               |    1
  1032.                  +-        Screen Width         -+
  1033.                  |                               |    2
  1034.                  +-------------------------------+
  1035.                  |                               |    3
  1036.                  +-        Screen Height        -+
  1037.                  |                               |    4
  1038.                  +---+-----------+---+-----------+
  1039.                  |Map| Color Res |R1 |Pixel Size |    5
  1040.                  +---+-----------+---+-----------+
  1041.                  |    Background Color Index     |    6
  1042.                  +---+---------------------------+
  1043.                  |Srt|    Pixel Aspect Ratio     |    7
  1044.                  +---+---------------------------+ 
  1045.  
  1046.                  where:
  1047.  
  1048.                  +------------+-------+---------------------------------+
  1049.                  |    Item    | Data  |           Description           |
  1050.                  |            | Type  |                                 |
  1051.                  +------------+-------+---------------------------------+
  1052.                  |Screen Width|integer|width, in pixels, of the logical |
  1053.                  |            |       |screen                           |
  1054.                  |            |       |                                 |
  1055.                  |            |       |Value:  1 to 65535               |
  1056.                  +------------+-------+---------------------------------+
  1057.                  |Screen      |integer|height, in pixels, of the logical|
  1058.                  |Height      |       |screen                           |
  1059.                  |            |       |                                 |
  1060.                  |            |       |Value:  1 to 65535               |
  1061.                  +------------+-------+---------------------------------+
  1062.                  |Map         |flag   |if set, a Global Color Map Block |
  1063.                  |            |       |follows the Logical Screen       |
  1064.                  |            |       |Descriptor Block; otherwise, an  |
  1065.                  |            |       |Extension Block or an Image      |
  1066.                  |            |       |Descriptor Block follows         |
  1067.                  +------------+-------+---------------------------------+
  1068.  
  1069.                  --------------------------------------------------------
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.                                                               (continued)
  1079.  
  1080.  GIF                                                   Revision 1.0, 5/88
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.                                       12
  1087.  
  1088.  2.2  Logical Screen Descriptor Block, continued
  1089.  ------------------------------------------------------------------------
  1090.  ------------------------------------------------------------------------
  1091.  
  1092.  Structure of    +------------+-------+---------------------------------+
  1093.  the Logical     |    Item    | Data  |           Description           |
  1094.  Screen          |            | Type  |                                 |
  1095.  Descriptor      +------------+-------+---------------------------------+
  1096.  Block           |Color Res   |field  |defines the number of bits per   |
  1097.  (continued)     |            |       |color component which the GIF    |
  1098.                  |            |       |encoding process had available   |
  1099.                  |            |       |for defining colors in the global|
  1100.                  |            |       |color map; is an indication of   |
  1101.                  |            |       |the richness of the palette from |
  1102.                  |            |       |which colors in the global color |
  1103.                  |            |       |map were chosen                  |
  1104.                  |            |       |                                 |
  1105.                  |            |       |Field value:  0 to 7             |
  1106.                  |            |       |Item value:   1 to 8 bits per    |
  1107.                  |            |       |  red, green, and blue color     |
  1108.                  |            |       |  component                      |
  1109.                  |            |       |                                 |
  1110.                  |            |       |Number of colors in the palette: |
  1111.                  |            |       |   (3 x item value)              |
  1112.                  |            |       |  2                              |
  1113.                  |            |       |  (8 to 16,000,000+)             |
  1114.                  +------------+-------+---------------------------------+
  1115.                  |R1          |n/a    |reserved; must be 0              |
  1116.                  +------------+-------+---------------------------------+
  1117.                  |Pixel Size  |field  |number of bits in each pixel of  |
  1118.                  |            |       |the images in the GIF data;      |
  1119.                  |            |       |determines the number of colors  |
  1120.                  |            |       |defined in the global color map  |
  1121.                  |            |       |(note:  does not indicate the    |
  1122.                  |            |       |number of colors actually used in|
  1123.                  |            |       |an image)                        |
  1124.                  |            |       |                                 |
  1125.                  |            |       |Field value:  0 to 7             |
  1126.                  |            |       |Item value:   1 to 8 bits per    |
  1127.                  |            |       |  pixel                          |
  1128.                  |            |       |                                 |
  1129.                  |            |       |Pixel value:                     |
  1130.                  |            |       |        (item value)             |
  1131.                  |            |       |  0 to 2             - 1         |
  1132.                  |            |       |  (maximum value of 255)         |
  1133.                  |            |       |                                 |
  1134.                  |            |       |Number of colors defined in the  |
  1135.                  |            |       |global color map:                |
  1136.                  |            |       |        (item value)             |
  1137.                  |            |       |  2 to 2                         |
  1138.                  |            |       |  (maximum value of 256)         |
  1139.                  +------------+-------+---------------------------------+
  1140.                  |Background  |byte   |pixel for the screen background  |
  1141.                  |Color Index |       |                                 |
  1142.                  +------------+-------+---------------------------------+
  1143.  
  1144.                  --------------------------------------------------------
  1145.  
  1146.                                                               (continued)
  1147.  
  1148.  GIF                                                   Revision 1.0, 5/88
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.                                       13
  1155.  
  1156.  2.2  Logical Screen Descriptor Block, continued
  1157.  ------------------------------------------------------------------------
  1158.  ------------------------------------------------------------------------
  1159.  
  1160.  Structure of    +------------+-------+---------------------------------+
  1161.  the Logical     |    Item    | Data  |           Description           |
  1162.  Screen          |            | Type  |                                 |
  1163.  Descriptor      +------------+-------+---------------------------------+
  1164.  Block           |Srt         |flag   |if set, the global color map is  |
  1165.  (continued)     |            |       |defined in sorted order, most    |
  1166.                  |            |       |used color first; otherwise, no  |
  1167.                  |            |       |assumption may be made about the |
  1168.                  |            |       |order of color definitions in the|
  1169.                  |            |       |global color map                 |
  1170.                  +------------+-------+---------------------------------+
  1171.                  |Pixel Aspect|field  |height to width ratio of each    |
  1172.                  |Ratio       |       |pixel of the source image; if 0  |
  1173.                  |            |       |no aspect ratio is specified     |
  1174.                  |            |       |                                 |
  1175.                  |            |       |Field value:  1 to 127           |
  1176.                  |            |       |Item value:                      |
  1177.                  |            |       |  (field value + 31) / 64        |
  1178.                  |            |       |Item value range:                |
  1179.                  |            |       |  32/64 to 158/64 (0.5 to 2.47)  |
  1180.                  +------------+-------+---------------------------------+
  1181.  
  1182.                  --------------------------------------------------------
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  GIF                                                   Revision 1.0, 5/88
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.                                       14
  1223.  
  1224.  2.3  Global Color Map Block
  1225.  ------------------------------------------------------------------------
  1226.  ------------------------------------------------------------------------
  1227.  
  1228.  Overview        The Global Color Map Block contains the global color
  1229.                  map.  The global color map is a series of red, green,
  1230.                  and blue intensity values that defines the individual
  1231.                  colors which may be used in an image.  The global color
  1232.                  map is used for each image in the GIF data unless a
  1233.                  local color map is defined for that image.  
  1234.  
  1235.                  --------------------------------------------------------
  1236.  
  1237.  Existence       The Global Color Map Block is optional.  If present, it
  1238.                  must immediately follow the Logical Screen Descriptor
  1239.                  Block and the MAP flag of the Logical Screen Descriptor
  1240.                  Block must be set.  
  1241.  
  1242.                  --------------------------------------------------------
  1243.  
  1244.  Size            The size, in bytes, of the Global Color Map Block is
  1245.                  three times the number of colors defined within.  The
  1246.                  number of colors defined may range from 2 to 256 and is
  1247.                  determined from the number of bits per pixel:
  1248.  
  1249.                                 (number of bits per pixel)
  1250.                                2
  1251.  
  1252.                  The number of bits per pixel is defined in the PIXEL
  1253.                  SIZE field of the Logical Screen Descriptor Block.
  1254.  
  1255.                  --------------------------------------------------------
  1256.  
  1257.  Structure of    The structure of the Global Color Map Block is
  1258.  the Global      illustrated below.
  1259.  Color Map
  1260.  Block                         Bits
  1261.  
  1262.                    7   6   5   4   3   2   1   0    Byte #
  1263.                  +---+---+---+---+---+---+---+---+
  1264.                  |     Color 0 Red Intensity     |    1
  1265.                  +-------------------------------+
  1266.                  |    Color 0 Green Intensity    |    2
  1267.                  +-------------------------------+
  1268.                  |    Color 0 Blue Intensity     |    3
  1269.                  +-------------------------------+
  1270.                  |     Color 1 Red Intensity     |    4
  1271.                  +-------------------------------+
  1272.                  |    Color 1 Green Intensity    |    5
  1273.                  +-------------------------------+
  1274.                  |    Color 1 Blue Intensity     |    6
  1275.                  +-------------------------------+ 
  1276.                  .                               .  repeat, as needed,
  1277.                  .                               .  for remaining colors
  1278.                  .                               .
  1279.                  +-------------------------------+
  1280.  
  1281.                  --------------------------------------------------------
  1282.                                                               (continued)
  1283.  
  1284.  GIF                                                   Revision 1.0, 5/88
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.                                       15
  1291.  
  1292.  2.3  Global Color Map Block, continued
  1293.  ------------------------------------------------------------------------
  1294.  ------------------------------------------------------------------------
  1295.  
  1296.  Structure of    where:
  1297.  the Global
  1298.  Color Map       +------------+-------+---------------------------------+
  1299.  Block           |    Item    | Data  |           Description           |
  1300.  (continued)     |            | Type  |                                 |
  1301.                  +------------+-------+---------------------------------+
  1302.                  |Color n     |byte   |indicates the amount of red      |
  1303.                  |Red         |       |component color n contains       |
  1304.                  |Intensity   |       |                                 |
  1305.                  |            |       |Item value range:  0 (no red)    |
  1306.                  |            |       |  to 255 (maximum red)           |
  1307.                  +------------+-------+------------------------